
/*
*本文件主要用于系统系统时预初始化操作
*
*/
#include "htsc_grpc_common_init.h"
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>

#include "htsc_grpc_properties_tools.h"
#include "htsc_grpc_conf.h"

static long htsc_grpc_consumer_maxrequest = 0;

//是否生成服务跟踪信息 1 生成 0 不生成
static int g_htsc_grpc_common_gentrace_enabled = 1;

//是否把生成的信息写kafka 1 写 0 不写（此时gentrace.enabled生效）
static int g_htsc_grpc_common_writekafka_enabled = 1;

//consumer端依赖服务版本
static char* g_htsc_grpc_common_consumer_service_version;

//获取是否生成服务跟踪信息参数
int htsc_grpc_common_get_gentrace_enabled() {
	return g_htsc_grpc_common_gentrace_enabled;
}

//获取是否生成服务跟踪信息参数
int htsc_grpc_common_get_writekafka_enabled() {
	return g_htsc_grpc_common_writekafka_enabled;
}

//获取consumer对服务版本要求
char * htsc_grpc_consumer_service_version_get() {
	return g_htsc_grpc_common_consumer_service_version;
}

void consumer_service_version_init() {
	size_t size = sizeof(char) * 1000;
	char *readbuff = (char*)malloc(size);

	//是否生成服务跟踪信息
	memset(readbuff, 0, size);
	htsc_grpc_properties_get_value(HTSC_GRPC_CONF_CONSUMER_SERVICE_VERSION, NULL, readbuff);
	if (readbuff == NULL || strlen(readbuff) == 0) {
		g_htsc_grpc_common_consumer_service_version = NULL;
		free(readbuff);
	}
	else {
		g_htsc_grpc_common_consumer_service_version = readbuff;
	}
}

/*
* 初始化通用入口
*/
void htsc_grpc_common_param_init() {
	//读取配置文件
	htsc_grpc_properties_init();
	
	size_t size = sizeof(char) * 1000;
	char *readbuff = (char*)malloc(size);

	//是否生成服务跟踪信息
	memset(readbuff, 0, size);
	htsc_grpc_properties_get_value(HTSC_GRPC_TRACE_GENTRACE_KEY, NULL, readbuff);
	if (readbuff == NULL || strcmp(readbuff, "") == 0 || strcmp(readbuff, "true") == 0) {
		g_htsc_grpc_common_gentrace_enabled = HTSC_GRPC_COMMON_YES;
	}
	else {
		g_htsc_grpc_common_gentrace_enabled = HTSC_GRPC_COMMON_NO;
	}

	//是否把服务跟踪信息发送kafka
	memset(readbuff, 0, size);
	htsc_grpc_properties_get_value(HTSC_GRPC_TRACE_WRITEKAFKA_KEY, NULL, readbuff);
	if (readbuff == NULL || strcmp(readbuff, "") == 0 || strcmp(readbuff, "true") == 0) {
		g_htsc_grpc_common_writekafka_enabled = HTSC_GRPC_COMMON_YES;
	}
	else {
		g_htsc_grpc_common_writekafka_enabled = HTSC_GRPC_COMMON_NO;
	}
	free(readbuff);

	consumer_service_version_init();
}




